<?php

class NddSession {
	public static function getSession() {

		$cfg = ezcConfigurationManager::getInstance();
		$cfg->init( 'ezcConfigurationIniReader', NDD_PATH );			//path to config.ini
		$dsn = $cfg->getSetting( 'config', 'database', 'dsn' );

		$db = ezcDbFactory::create( $dsn );
		ezcDbInstance::set( $db );
		
		//retrieve or create the session
		try {
			$session = ezcPersistentSessionInstance::get();
		}
		catch(ezcPersistentSessionNotFoundException $e) {
			$session =  new ezcPersistentSession(
				ezcDbInstance::get(),
				new ezcPersistentCacheManager( new ezcPersistentCodeManager( NDD_PATH."/lib/classes/db/definitions/" ) )
			);
			ezcPersistentSessionInstance::set( $session );
		}
		
		return $session;
	}
}

?>